package org.thinker.web;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import org.thinker.service.board.BoardService;
import org.thinker.util.MyCriteria;
import org.thinker.vo.BoardVO;

@Controller
@RequestMapping(value="/board")
public class BoardController {
	
	@Resource(name="boardService")
	private BoardService boardService;
	
	@RequestMapping(method=RequestMethod.GET, params="cmd=list")
	public ModelAndView boardList(int pageNo)throws Exception{
		
		ModelAndView mav = new ModelAndView();
		MyCriteria cri = new MyCriteria(1);
		try{
			List<BoardVO> boardList = boardService.listBoard(cri);
			mav.setViewName("boardlist");
			mav.addObject("boardList", boardList);
		}catch(Exception e){
			e.printStackTrace();
		}
		return mav;
	}
	
	@RequestMapping(method=RequestMethod.GET, params="cmd=write")
	public String boardWriteForm()throws Exception{
		System.out.println("GET");
		System.out.println("GET");System.out.println("GET");System.out.println("GET");
		return "boardwriteform";
	}
	
	@RequestMapping(method=RequestMethod.POST, params="cmd=write")
	public ModelAndView boardWriteAction(BoardVO vo)throws Exception{
		
		ModelAndView mav = new ModelAndView();
		try{
			boardService.writeBoard(vo);
			mav.setViewName("boardwritesuccess");
		}catch(Exception e){
			e.printStackTrace();
			mav.setViewName("error.jsp");
		}
		
		return mav;
	}
	

}









